package com.suwish.pc.ui.component.tab;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicPanelUI;

public class TabPanelUI extends BasicPanelUI {

    private boolean selected;
    private boolean hideBorder;
    private Color fillerColor;
    private Color border;

    // ------------------------------------------------------------------------------------------------------------------
    //  Custom installation methods
    // ------------------------------------------------------------------------------------------------------------------
    protected void installDefaults(JPanel p) {
        p.setOpaque(false);
    }

    // ------------------------------------------------------------------------------------------------------------------
    //  Custom painting methods
    // ------------------------------------------------------------------------------------------------------------------
    public void paint(Graphics g, JComponent c) {
        //Color borderColor = getBorderColor();
//    	Color borderColor = new Color(135,238,255);
    	//Color borderColor = Color.RED;
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Insets vInsets = c.getInsets();

        int w = c.getWidth() - (vInsets.left + vInsets.right);
        
        int h = c.getHeight() - (vInsets.top + vInsets.bottom);

        int x = vInsets.left;
        int y = vInsets.top;

        Color endColor;
        Color startColor;

        if (selected) {
        	startColor = new Color(122,216,244);
        	endColor = new Color(81,197,221);
        	x = vInsets.left-1;
        }
        else {
        	//设置tab颜色
        	startColor = UIManager.getColor("Panel.background");// new Color(122,216,244);
        	endColor = UIManager.getColor("Panel.background");//new Color(81,197,221);
        }
//
//        GradientPaint paint = new GradientPaint(0, 0, endColor, 0, h, endColor, true);
        GradientPaint p = new GradientPaint(0,0,startColor, 0, h, endColor,true);
        g2d.setPaint(p);           

        g2d.fillRect(x, y, w, h);

        if (selected) {
            // Draw border on right side.
            g2d.setColor(Color.BLACK);
//            g2d.drawLine(w - 1, 0, w - 1, h);
            g2d.drawRect(0, 0, w, h);
        }else {//if (!hideBorder) {
            // Draw border on right side.
            g2d.setColor(Color.LIGHT_GRAY);
            g2d.drawLine(w - 1, 1, w - 1, h - 1);
        }
        
    }


    public void setHideBorder(boolean hide) {
        hideBorder = hide;
    }
    
    public void setSelected(boolean selected) {
        this.selected = selected;
    }
    
    public void setPlacement(int placement) {
       
    }


    public Color getFillerColor() {
        return fillerColor;
    }

    public void setFillerColor(Color fillerColor) {
        this.fillerColor = fillerColor;
    }

    public Color getBorder() {
        return border;
    }

    public void setBorder(Color border) {
        this.border = border;
    }
}
